package Classes.GameUtils
{
	import Classes.GameDatas.GD_Item;
	import Classes.GameViews.ViewIcons.ViewIcon;
	import Classes.GameViews.ViewPanels.VP_Main;
	import Classes.Managers.M_Communication;
	import Classes.Managers.M_ConfigData;
	import Classes.staticinfo.Language;
	
	import flash.display.DisplayObject;
	import flash.events.TimerEvent;
	import flash.utils.Timer;

	/** 
	 * @author thy
	 * @version 1.0.0 
	 * 创建时间：May 22, 2012 7:39:58 PM 
	 */ 
	public class GU_DealPlaySpeed 
	{
		private var _speedTime:int;
		public var flag:Boolean=false;
		
		private static var _instance:GU_DealPlaySpeed;
		
		private var timer:Timer;
		
		public function GU_DealPlaySpeed(){}
		
		public static function get instance():GU_DealPlaySpeed
		{
			if(!_instance)_instance=new GU_DealPlaySpeed();
			return _instance;
		}
	
		public function get speedTime():int
		{
			return _speedTime;
		}

		public function set speedTime(value:int):void//秒
		{
			_speedTime = value;
			if(value>0)
			{
				var obj:Object= GD_Item.getItemConfigDataByType(M_ConfigData.instance.addSpeedItem);
				var countPic:ViewIcon=ViewIcon.creat({sourceName:obj.zt_item_source,picName:obj.zt_item_pic});
				countPic.iHeight=27;
				countPic.iWidth=27;
				countPic.width=27;
				countPic.height=27;
				VP_Main.instance.setPlayerEle2(countPic);
				this.tmpTimer=value;
				
				this.flag=true;
				timer=null;
				timer=new Timer(1000,value);
				timer.addEventListener(TimerEvent.TIMER,timerFun);
				timer.addEventListener(TimerEvent.TIMER_COMPLETE,overHanld);
				this.timer.start();
				
				tips=Language.jiasuItem.replace("@itemName",obj.zt_item_name);
				tips=tips.replace("@t",M_ConfigData.instance.addSpeedTimer);
//				recordTimer();
				var min:int=value/60;
				var ms:int=value%60;
				ToolTip_Sprite.getInstance().setTip(VP_Main.instance.getPlayerEle2Tips(),new MyTipSprite(tips+min+":"+ms),ToolTip_Sprite.DIRECTION_DOWN,true);
				
			}else{
				VP_Main.instance.setPlayerEle2(null);
			}
		}
		
		private var tips:String;
		private var lastTimer:String="";
		private var tmpTimer:int;
		private function timerFun(e:TimerEvent):void
		{
//			jiasuItem
			this.tmpTimer-=1;
			var min:int=tmpTimer/60;
			var ms:int=tmpTimer%60;
			this.lastTimer=min+":"+ms;
			ToolTip_Sprite.getInstance().setTipTxt(tips+lastTimer,VP_Main.instance.getPlayerEle2Tips());
		}
			
			
		private function overHanld(e:TimerEvent):void
		{
			VP_Main.instance.setPlayerEle2(null);
			this.flag=false;
			this.timer.stop();
			timer.removeEventListener(TimerEvent.TIMER,timerFun);
			this.timer.removeEventListener(TimerEvent.TIMER_COMPLETE,overHanld);
			this.timer=null;
			M_Communication.instance.send(128008);
		}
		
	}
}
